package com.lottery.game.core.modules.service.game.impl;

import com.lottery.game.common.base.service.impl.AbstractBaseLogicServiceImpl;
import com.lottery.game.core.modules.entity.game.GameUserSendMessageRecord;
import com.lottery.game.core.modules.service.game.GameUserSendMessageRecordService;

import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

import tk.mybatis.mapper.entity.Example;

@Service("gameUserSendMessageRecordService")
public class GameUserSendMessageRecordServiceImpl extends AbstractBaseLogicServiceImpl<GameUserSendMessageRecord> implements GameUserSendMessageRecordService {
    @Override
    public boolean canSend(String phone) {
        Date hourDate = DateUtils.addHours(new Date(), -1);
        Example example = new Example(GameUserSendMessageRecord.class);
        example.createCriteria().andGreaterThan("serverCreateTime", hourDate).andEqualTo("phone", phone);
        return selectCountByExample(example) < 3;
    }

    @Override
    public boolean canSendMin(String phone) {
        Date minDate = DateUtils.addMinutes(new Date(), -1);
        Example example = new Example(GameUserSendMessageRecord.class);
        example.createCriteria().andGreaterThan("serverCreateTime", minDate).andEqualTo("phone", phone);
        return selectCountByExample(example) < 1;
    }
}
